home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
Mandlebrot
/
Mandlebrot Folder
/
DrawMandel.c
< prev
next >
Wrap
Text File
|
1990-05-09
|
5KB
|
222 lines
/* *********************************************************************************
FILE: DrawMandel.c
DESCRIPTION: DrawMandel is the main loop. Picks a color using the value
calculated by CalcMandel to index into the system CLUT.
Then uses the toolbox call RGBForeColor to set the rectangle
color and finally a call to LineTo. This version doesn't require
a 68881.
AUTHOR: Bruce E. Gladstone
Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
Revision History:
============================================================
5/1/90 - Release to Compuserve
============================================================
COMMENTS:
None.
******************************************************************************** */
#include <stdio.h>
#include <MacTypes.h>
#include <WindowMgr.h>
#include <MenuMgr.h>
#include <EventMgr.h>
#include <ToolboxUtil.h>
#include <ControlMgr.h>
#include <color.h>
#include <colortoolbox.h>
#include "Mandelbrot.h"
/* ---------------------------- Global Variables ---------------------------------- */
extern int colorQD;
extern int quitFlag;
extern int linearFlag;
extern int custPict;
extern int numColorBits;
extern int numColors, brushSize;
extern int limit;
extern int n;
extern long startTime, now;
extern float res;
extern float centx, centy;
extern float xmin, xmax, ymin, ymax;
extern float delx, dely;
/* ---------------------------- Global MacTypes ----------------------------------- */
extern Str255 str;
extern CTabHandle myColorHandle;
extern RGBColor aColor;
extern Rect myRect, dragRect;
extern WindowPtr aboutWindow;
extern MenuHandle appleMenu, mandelMenu, editMenu, xMenu, yMenu, resMenu, timeMenu;
extern WindowPtr myWindow;
/* --------------------------- Local Prototypes --------------------------------- */
void drawMandel ( void );
int calcMandel ( float, float );
int eventCheck ( void );
void updateMenus ( void );
/* --------------------------------------------------------------------------------
DrawMandel - 5/01/90 beg
-------------------------------------------------------------------------------- */
void
drawMandel()
{
long n, nx, ny;
long xres, yres;
float x, y, del;
Rect aRect;
int eventResult;
myRect = (*myWindow).portRect;
xres = myRect.right;
yres = myRect.bottom;
xmin = centx - res;
xmax = centx + res;
ymin = centy - res;
ymax = centy + res;
delx = ( xmax - xmin )/( xres+1 );
dely = ( ymax - ymin )/( yres+1 );
if ( delx > dely )
{
dely = delx;
}
else
{
delx = dely;
}
PenSize ( brushSize , brushSize );
del = delx*brushSize;
y = ymin;
ny = 0;
nx = 0;
while ( ny < ( yres - 1 ))
{
x = xmin;
nx = 0;
while ( nx < ( xres - 1 ))
{
n = calcMandel ( x,y );
if ( colorQD && (numColorBits > 2 )) /* color version */
{
if ( linearFlag )
{
if (( n == 0 ) || ( n >= limit ))
{
n = numColors - 1;
}
else
{
n = n * numColors / limit;
}
}
else
{
if (( n == 0 ) || ( n >= limit ))
{
n = numColors - 1;
}
else
{
n = n % numColors;
}
}
aColor = (**myColorHandle).ctTable[n].rgb;
RGBForeColor ( &aColor );
LineTo ( nx, ny );
}
else /* black and white version */
{
if (( n == 0 ) || ( n >= 256 ))
{
PenPat ( black );
}
else if ( n > 50 )
{
PenPat ( dkGray );
}
else if ( n > 10 )
{
PenPat ( gray );
}
else if ( n > 2 )
{
PenPat ( ltGray );
}
else
{
PenPat ( white );
}
LineTo ( nx+brushSize, ny );
}
if ( eventCheck () || quitFlag == TRUE ) goto breakOut;
nx = nx + brushSize; /* end of nx loop */
x = x + del;
}
ny = ny + brushSize; /* end of ny loop */
y = y + del;
MoveTo ( 0, ny );
}
breakOut:
{
EraseRect ( &myRect );
MoveTo ( 0,0 );
now = ( TickCount() - startTime )/60;
updateMenus(); /* Call update here so we can record time */
}
} /* drawMandel() */
/* --------------------------------------------------------------------------------
calcMandel - 5/01/90 beg
calcMandel determines the color index for the line to be drawn
----------------------------------------------------------------------------------- */
int calcMandel ( creal, cimag )
float creal, cimag;
{
register int count;
float zr2, zi2;
float zreal, zimag;
float zreal1, zreal2;
zreal = creal;
zimag = cimag;
zreal1 = 100.0;
zreal2 = 200.0;
for ( count = 1; count <= limit; count++ )
{
zr2 = zreal*zreal;
zi2 = zimag*zimag;
if (( zr2 + zi2 ) > 4.0 ) break;
zimag = 2*zreal*zimag + cimag;
zreal = zr2 - zi2 + creal;
if ( zreal == zreal2 )
{
count = 0;
break;
}
zreal2 = zreal1;
zreal1 = zreal;
}
return ( count );
} /* int calcMandel ( creal, cimag ) */
/* =============================== EOF ==========================================
Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
================================================================================ */